home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / game / shoot / ADoom_src_1_1.lha / ADoom_src / p_switch.c < prev    next >
C/C++ Source or Header  |  1997-12-25  |  13KB  |  655 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. //
  18. // $Log:$
  19. //
  20. // DESCRIPTION:
  21. //    Switches, buttons. Two-state animation. Exits.
  22. //
  23. //-----------------------------------------------------------------------------
  24.  
  25. static const char
  26. rcsid[] = "$Id: p_switch.c,v 1.3 1997/01/28 22:08:29 b1 Exp $";
  27.  
  28.  
  29. #include "i_system.h"
  30. #include "doomdef.h"
  31. #include "p_local.h"
  32.  
  33. #include "g_game.h"
  34.  
  35. #include "s_sound.h"
  36.  
  37. // Data.
  38. #include "sounds.h"
  39.  
  40. // State.
  41. #include "doomstat.h"
  42. #include "r_state.h"
  43.  
  44.  
  45. //
  46. // CHANGE THE TEXTURE OF A WALL SWITCH TO ITS OPPOSITE
  47. //
  48. switchlist_t alphSwitchList[] =
  49. {
  50.     // Doom shareware episode 1 switches
  51.     {"SW1BRCOM",    "SW2BRCOM",    1},
  52.     {"SW1BRN1",    "SW2BRN1",    1},
  53.     {"SW1BRN2",    "SW2BRN2",    1},
  54.     {"SW1BRNGN",    "SW2BRNGN",    1},
  55.     {"SW1BROWN",    "SW2BROWN",    1},
  56.     {"SW1COMM",    "SW2COMM",    1},
  57.     {"SW1COMP",    "SW2COMP",    1},
  58.     {"SW1DIRT",    "SW2DIRT",    1},
  59.     {"SW1EXIT",    "SW2EXIT",    1},
  60.     {"SW1GRAY",    "SW2GRAY",    1},
  61.     {"SW1GRAY1",    "SW2GRAY1",    1},
  62.     {"SW1METAL",    "SW2METAL",    1},
  63.     {"SW1PIPE",    "SW2PIPE",    1},
  64.     {"SW1SLAD",    "SW2SLAD",    1},
  65.     {"SW1STARG",    "SW2STARG",    1},
  66.     {"SW1STON1",    "SW2STON1",    1},
  67.     {"SW1STON2",    "SW2STON2",    1},
  68.     {"SW1STONE",    "SW2STONE",    1},
  69.     {"SW1STRTN",    "SW2STRTN",    1},
  70.     
  71.     // Doom registered episodes 2&3 switches
  72.     {"SW1BLUE",    "SW2BLUE",    2},
  73.     {"SW1CMT",        "SW2CMT",    2},
  74.     {"SW1GARG",    "SW2GARG",    2},
  75.     {"SW1GSTON",    "SW2GSTON",    2},
  76.     {"SW1HOT",        "SW2HOT",    2},
  77.     {"SW1LION",    "SW2LION",    2},
  78.     {"SW1SATYR",    "SW2SATYR",    2},
  79.     {"SW1SKIN",    "SW2SKIN",    2},
  80.     {"SW1VINE",    "SW2VINE",    2},
  81.     {"SW1WOOD",    "SW2WOOD",    2},
  82.     
  83.     // Doom II switches
  84.     {"SW1PANEL",    "SW2PANEL",    3},
  85.     {"SW1ROCK",    "SW2ROCK",    3},
  86.     {"SW1MET2",    "SW2MET2",    3},
  87.     {"SW1WDMET",    "SW2WDMET",    3},
  88.     {"SW1BRIK",    "SW2BRIK",    3},
  89.     {"SW1MOD1",    "SW2MOD1",    3},
  90.     {"SW1ZIM",        "SW2ZIM",    3},
  91.     {"SW1STON6",    "SW2STON6",    3},
  92.     {"SW1TEK",        "SW2TEK",    3},
  93.     {"SW1MARB",    "SW2MARB",    3},
  94.     {"SW1SKULL",    "SW2SKULL",    3},
  95.     
  96.     {"\0",        "\0",        0}
  97. };
  98.  
  99. int        switchlist[MAXSWITCHES * 2];
  100. int        numswitches;
  101. button_t        buttonlist[MAXBUTTONS];
  102.  
  103. //
  104. // P_InitSwitchList
  105. // Only called at game initialization.
  106. //
  107. void P_InitSwitchList(void)
  108. {
  109.     int        i;
  110.     int        index;
  111.     int        episode;
  112.     
  113.     episode = 1;
  114.  
  115.     if (gamemode == registered)
  116.     episode = 2;
  117.     else
  118.     if ( gamemode == commercial )
  119.         episode = 3;
  120.         
  121.     for (index = 0,i = 0;i < MAXSWITCHES;i++)
  122.     {
  123.     if (!alphSwitchList[i].episode)
  124.     {
  125.         numswitches = index/2;
  126.         switchlist[index] = -1;
  127.         break;
  128.     }
  129.         
  130.     if (alphSwitchList[i].episode <= episode)
  131.     {
  132. #if 0    // UNUSED - debug?
  133.         int        value;
  134.             
  135.         if (R_CheckTextureNumForName(alphSwitchList[i].name1) < 0)
  136.         {
  137.         I_Error("Can't find switch texture '%s'!",
  138.             alphSwitchList[i].name1);
  139.         continue;
  140.         }
  141.         
  142.         value = R_TextureNumForName(alphSwitchList[i].name1);
  143. #endif
  144.         switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name1);
  145.         switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name2);
  146.     }
  147.     }
  148. }
  149.  
  150.  
  151. //
  152. // Start a button counting down till it turns off.
  153. //
  154. void
  155. P_StartButton
  156. ( line_t*    line,
  157.   bwhere_e    w,
  158.   int        texture,
  159.   int        time )
  160. {
  161.     int        i;
  162.     
  163.     // See if button is already pressed
  164.     for (i = 0;i < MAXBUTTONS;i++)
  165.     {
  166.     if (buttonlist[i].btimer
  167.         && buttonlist[i].line == line)
  168.     {
  169.         
  170.         return;
  171.     }
  172.     }
  173.     
  174.  
  175.     
  176.     for (i = 0;i < MAXBUTTONS;i++)
  177.     {
  178.     if (!buttonlist[i].btimer)
  179.     {
  180.         buttonlist[i].line = line;
  181.         buttonlist[i].where = w;
  182.         buttonlist[i].btexture = texture;
  183.         buttonlist[i].btimer = time;
  184.         buttonlist[i].soundorg = (mobj_t *)&line->frontsector->soundorg;
  185.         return;
  186.     }
  187.     }
  188.     
  189.     I_Error("P_StartButton: no button slots left!");
  190. }
  191.  
  192.  
  193.  
  194.  
  195.  
  196. //
  197. // Function that changes wall texture.
  198. // Tell it if switch is ok to use again (1=yes, it's a button).
  199. //
  200. void
  201. P_ChangeSwitchTexture
  202. ( line_t*    line,
  203.   int         useAgain )
  204. {
  205.     int     texTop;
  206.     int     texMid;
  207.     int     texBot;
  208.     int     i;
  209.     int     sound;
  210.     
  211.     if (!useAgain)
  212.     line->special = 0;
  213.  
  214.     texTop = sides[line->sidenum[0]].toptexture;
  215.     texMid = sides[line->sidenum[0]].midtexture;
  216.     texBot = sides[line->sidenum[0]].bottomtexture;
  217.     
  218.     sound = sfx_swtchn;
  219.  
  220.     // EXIT SWITCH?
  221.     if (line->special == 11)                
  222.     sound = sfx_swtchx;
  223.     
  224.     for (i = 0;i < numswitches*2;i++)
  225.     {
  226.     if (switchlist[i] == texTop)
  227.     {
  228.         S_StartSound(buttonlist->soundorg,sound);
  229.         sides[line->sidenum[0]].toptexture = switchlist[i^1];
  230.  
  231.         if (useAgain)
  232.         P_StartButton(line,top,switchlist[i],BUTTONTIME);
  233.  
  234.         return;
  235.     }
  236.     else
  237.     {
  238.         if (switchlist[i] == texMid)
  239.         {
  240.         S_StartSound(buttonlist->soundorg,sound);
  241.         sides[line->sidenum[0]].midtexture = switchlist[i^1];
  242.  
  243.         if (useAgain)
  244.             P_StartButton(line, middle,switchlist[i],BUTTONTIME);
  245.  
  246.         return;
  247.         }
  248.         else
  249.         {
  250.         if (switchlist[i] == texBot)
  251.         {
  252.             S_StartSound(buttonlist->soundorg,sound);
  253.             sides[line->sidenum[0]].bottomtexture = switchlist[i^1];
  254.  
  255.             if (useAgain)
  256.             P_StartButton(line, bottom,switchlist[i],BUTTONTIME);
  257.  
  258.             return;
  259.         }
  260.         }
  261.     }
  262.     }
  263. }
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. //
  271. // P_UseSpecialLine
  272. // Called when a thing uses a special line.
  273. // Only the front sides of lines are usable.
  274. //
  275. boolean
  276. P_UseSpecialLine
  277. ( mobj_t*    thing,
  278.   line_t*    line,
  279.   int        side )
  280. {               
  281.  
  282.     // Err...
  283.     // Use the back sides of VERY SPECIAL lines...
  284.     if (side)
  285.     {
  286.     switch(line->special)
  287.     {
  288.       case 124:
  289.         // Sliding door open&close
  290.         // UNUSED?
  291.         break;
  292.  
  293.       default:
  294.         return false;
  295.         break;
  296.     }
  297.     }
  298.  
  299.     
  300.     // Switches that other things can activate.
  301.     if (!thing->player)
  302.     {
  303.     // never open secret doors
  304.     if (line->flags & ML_SECRET)
  305.         return false;
  306.     
  307.     switch(line->special)
  308.     {
  309.       case 1:     // MANUAL DOOR RAISE
  310.       case 32:    // MANUAL BLUE
  311.       case 33:    // MANUAL RED
  312.       case 34:    // MANUAL YELLOW
  313.         break;
  314.         
  315.       default:
  316.         return false;
  317.         break;
  318.     }
  319.     }
  320.  
  321.     
  322.     // do something  
  323.     switch (line->special)
  324.     {
  325.     // MANUALS
  326.       case 1:        // Vertical Door
  327.       case 26:        // Blue Door/Locked
  328.       case 27:        // Yellow Door /Locked
  329.       case 28:        // Red Door /Locked
  330.  
  331.       case 31:        // Manual door open
  332.       case 32:        // Blue locked door open
  333.       case 33:        // Red locked door open
  334.       case 34:        // Yellow locked door open
  335.  
  336.       case 117:        // Blazing door raise
  337.       case 118:        // Blazing door open
  338.     EV_VerticalDoor (line, thing);
  339.     break;
  340.     
  341.     //UNUSED - Door Slide Open&Close
  342.     // case 124:
  343.     // EV_SlidingDoor (line, thing);
  344.     // break;
  345.  
  346.     // SWITCHES
  347.       case 7:
  348.     // Build Stairs
  349.     if (EV_BuildStairs(line,build8))
  350.         P_ChangeSwitchTexture(line,0);
  351.     break;
  352.  
  353.       case 9:
  354.     // Change Donut
  355.     if (EV_DoDonut(line))
  356.         P_ChangeSwitchTexture(line,0);
  357.     break;
  358.     
  359.       case 11:
  360.     // Exit level
  361.     P_ChangeSwitchTexture(line,0);
  362.     G_ExitLevel ();
  363.     break;
  364.     
  365.       case 14:
  366.     // Raise Floor 32 and change texture
  367.     if (EV_DoPlat(line,raiseAndChange,32))
  368.         P_ChangeSwitchTexture(line,0);
  369.     break;
  370.     
  371.       case 15:
  372.     // Raise Floor 24 and change texture
  373.     if (EV_DoPlat(line,raiseAndChange,24))
  374.         P_ChangeSwitchTexture(line,0);
  375.     break;
  376.     
  377.       case 18:
  378.     // Raise Floor to next highest floor
  379.     if (EV_DoFloor(line, raiseFloorToNearest))
  380.         P_ChangeSwitchTexture(line,0);
  381.     break;
  382.     
  383.       case 20:
  384.     // Raise Plat next highest floor and change texture
  385.     if (EV_DoPlat(line,raiseToNearestAndChange,0))
  386.         P_ChangeSwitchTexture(line,0);
  387.     break;
  388.     
  389.       case 21:
  390.     // PlatDownWaitUpStay
  391.     if (EV_DoPlat(line,downWaitUpStay,0))
  392.         P_ChangeSwitchTexture(line,0);
  393.     break;
  394.     
  395.       case 23:
  396.     // Lower Floor to Lowest
  397.     if (EV_DoFloor(line,lowerFloorToLowest))
  398.         P_ChangeSwitchTexture(line,0);
  399.     break;
  400.     
  401.